package bamin.com.bamindaijia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;

import java.util.List;

import bamin.com.bamindaijia.R;
import bamin.com.bamindaijia.model.HistoryEndSite;

import static bamin.com.bamindaijia.R.id.textView_detail;
import static bamin.com.bamindaijia.R.id.textView_poi;

/**
 * Created by Administrator on 2016/9/27.
 */

public class MyChooseAdapter extends BaseAdapter {

    private List<PoiItem> mPois;
    private List<HistoryEndSite> mHistoryEndSiteList;
    private LayoutInflater inflater;
    private int type;

    class ViewHolder {
        TextView textView_poi;
        TextView textView_detail;
    }

    public MyChooseAdapter(Context context, List<PoiItem> mPois) {
        this.mPois = mPois;
        inflater = LayoutInflater.from(context);
    }

    public MyChooseAdapter(Context context, List<HistoryEndSite> mHistoryEndSiteList, int type) {
        this.mHistoryEndSiteList = mHistoryEndSiteList;
        inflater = LayoutInflater.from(context);
        this.type = type;
    }

    @Override
    public int getCount() {
        if (type == 1) {
            return mHistoryEndSiteList.size();
        }
        return mPois.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.site_item, null);
            holder.textView_poi = (TextView) convertView.findViewById(textView_poi);
            holder.textView_detail = (TextView) convertView.findViewById(textView_detail);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (type == 1) {
            if (mHistoryEndSiteList.size()>0){
                holder.textView_poi.setText(mHistoryEndSiteList.get(position).getName());
                holder.textView_detail.setText(mHistoryEndSiteList.get(position).getAddress());
            }
        } else {
            if (mPois.size() > 0) {
                holder.textView_poi.setText(mPois.get(position).getTitle());
                holder.textView_detail.setText(mPois.get(position).getSnippet());
            }
        }
        return convertView;
    }
}
